/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : Feb 26, 2012  1:43:30 PM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : jpa.service.promis.common
 * File Name : CostBuildingPhaseServices.java
 * TODO
 */
package jpa.service.promis.common;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;

import org.apache.log4j.Logger;

import promis.utility.CommonService;
import jpa.entitys.common.CommonEntity;
import jpa.entitys.promis.common.CostBuildingPhase;
import jpa.entitys.promis.common.CostBuildingPhasePK;
import jpa.service.common.JPAService;

/**
 * @author chatree
 *
 */
public class CostBuildingPhaseServices extends JPAService {	
	
	private static final Logger log = Logger.getLogger(CostBuildingPhaseServices.class);

	/**
	 * @param em
	 */
	public CostBuildingPhaseServices(EntityManager em) {
		super(em);
		// TODO Auto-generated constructor stub
	}
	

	public CostBuildingPhase FindByKey(CostBuildingPhasePK costBuildingPhasePk ) throws Exception 
	{					
		return super.ConvertToYoureObject(super.find(costBuildingPhasePk, "CostBuildingPhase.findById"));
	}
	
	public CostBuildingPhase InsertedOrUpdated(CostBuildingPhase vlaue) throws Exception {
		CostBuildingPhase obj = vlaue;
		try{		
			if(CommonService.IsNull(obj.getLastUpdOn()))
			{						
				super.inserted(obj);
			}else{						
				super.updated(obj);
			}
		}catch(Exception e)
		{
			log.error(e);
			throw e;
		}
		return obj;
	}
	
	public List<CostBuildingPhase> Inserted(List<CostBuildingPhase> vlauelist) throws Exception {
		
		try{
			List<CommonEntity> common_lst = new ArrayList<CommonEntity>();			
			for(CostBuildingPhase obj : vlauelist)
			{
				if(CommonService.IsNull(obj.getLastUpdOn()))
				{								
					common_lst.add(obj);
				}
			}		
			
			if(CommonService.getSize(common_lst) > 0)
				super.inserted(common_lst);
			
		}catch(Exception e)
		{
			log.error(e);
			throw e;
		}
		return vlauelist;
	}
	
	public List<CostBuildingPhase> Updated(List<CostBuildingPhase> vlauelist) throws Exception {		
		
		try{
			List<CommonEntity> common_lst = new ArrayList<CommonEntity>();
			for(CostBuildingPhase obj : vlauelist)
				common_lst.add(obj);
			
			if(CommonService.getSize(common_lst) > 0)
				super.updated(common_lst);			
			
		}catch(Exception e)
		{
			log.error(e);
			throw e;
		}
		return vlauelist;
	}


}
